HAL GFXTIM initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:
Open STM32CubeMX2 GFXTIM configuration panel.
Configure the SW layer HAL.
Configure the GFXTIM advanced features.
Configure the NVIC if the application requires the GFXTIM to be used in IT mode.
Generate the code.
Note
The configuration below might vary from a series to another.
HAL GFXTIM configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL GFXTIM advanced features configuration ¶
Configure the advanced GFXTIM features.
HAL GFXTIM security and privilege features configuration ¶
Configure the GFXTIM security and privilege features if needed.
NVIC configuration ¶
Configure the NVIC in case of an interrupt.
Generated GFXTIM initialization and de-initialization sequences ¶
The GFXTIM initialization sequence is generated in the
mx_gfxtim_init
function in
mx_gfxtim.c
file
under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
Code Snippet HAL1 |
Code Snippet HAL2 |
|---|---|---|
|
Handle declaration |
GFXTIM_HandleTypeDef hgfxtim;
|
hal_gfxtim_handle_t hGFXTIM;
|
|
Initialization and configuration sequence |
static void MX_GFXTIM_Init(void)
{
hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
if (HAL_GFXTIM_Init(&hgfxtim) != HAL_OK)
{
Error_Handler();
}
pClockGeneratorConfig.LCCHwReloadSrc = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
pClockGeneratorConfig.LCCReloadValue = 159999;
pClockGeneratorConfig.LCCClockSrc = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
pClockGeneratorConfig.LineClockSrc = GFXTIM_LINE_CLK_SRC_LCC_UNDERFLOW;
pClockGeneratorConfig.FrameClockSrc = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
pClockGeneratorConfig.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
pClockGeneratorConfig.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
if (HAL_GFXTIM_ClockGenerator_Config(&hgfxtim, &pClockGeneratorConfig) != HAL_OK)
{
Error_Handler();
}
pAbsoluteTimerConfig.LineCounterValue = 0;
pAbsoluteTimerConfig.LineCompare1Value = 1500;
pAbsoluteTimerConfig.LineCompare2Value = 3000;
pAbsoluteTimerConfig.FrameCompare1Value = 0;
pAbsoluteTimerConfig.FrameCounterValue = 0;
pAbsoluteTimerConfig.FrameOverflowInterrupt = DISABLE;
pAbsoluteTimerConfig.FrameCompare1Interrupt = DISABLE;
pAbsoluteTimerConfig.LineOverflowInterrupt = DISABLE;
pAbsoluteTimerConfig.LineCompare1Interrupt = ENABLE;
pAbsoluteTimerConfig.LineCompare2Interrupt = ENABLE;
if (HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim, &pAbsoluteTimerConfig) != HAL_OK)
{
Error_Handler();
}
}
void HAL_GFXTIM_MspInit(GFXTIM_HandleTypeDef* hgfxtim)
{
if(hgfxtim->Instance==GFXTIM)
{
/* Peripheral clock enable */
__HAL_RCC_GFXTIM_CLK_ENABLE();
/* GFXTIM interrupt Init */
HAL_NVIC_SetPriority(GFXTIM_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(GFXTIM_IRQn);
}
}
|
hal_gfxtim_handle_t *mx_gfxtim_hal_init(void)
{
hal_gfxtim_clkgen_frame_config_t p_frame_clk_config;
hal_gfxtim_clkgen_line_config_t p_line_clk_config;
HAL_RCC_GFXTIM_EnableClock();
if (HAL_GFXTIM_Init(&hGFXTIM, HAL_GFXTIM) != HAL_OK)
{
return NULL;
}
p_line_clk_config.reload_src = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
p_line_clk_config.reload_val = 0x270FFU;
p_line_clk_config.counter_src = HAL_GFXTIM_CLKGEN_LINE_COUNT_GFXTIMHCLK;
p_line_clk_config.clock_src = HAL_GFXTIM_CLKGEN_LINE_LCNT_UNDERFLOW;
p_frame_clk_config.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
p_frame_clk_config.reload_val = 0x000U;
p_frame_clk_config.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
p_frame_clk_config.clock_src = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
if (HAL_GFXTIM_CLKGEN_SetConfigLineFrameClock(&hGFXTIM, &p_frame_clk_config, &p_line_clk_config) != HAL_OK)
{
return NULL;
}
if (HAL_GFXTIM_ABSTIM_SetLineCounter(&hGFXTIM, 0x000U) != HAL_OK)
{
return NULL;
}
if (HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hGFXTIM, HAL_GFXTIM_ABSTIM_LINE_COMP_1, 0x5DCU) != HAL_OK)
{
return NULL;
}
if (HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hGFXTIM, HAL_GFXTIM_ABSTIM_LINE_COMP_2, 0xBB8U) != HAL_OK)
{
return NULL;
}
/* Enable the interruption for GFXTIM */
HAL_CORTEX_NVIC_SetPriority(GFXTIM_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0, HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(GFXTIM_IRQn);
return &hGFXTIM;
}
|
|
Deinitialization sequence |
void MX_GFXTIM_DeInit(void)
{
if (HAL_GFXTIM_DeInit(&hgfxtim) != HAL_OK)
{
Error_Handler();
}
}
void HAL_GFXTIM_MspDeInit(GFXTIM_HandleTypeDef* hgfxtim)
{
if(hgfxtim->Instance==GFXTIM)
{
/* Peripheral clock disable */
__HAL_RCC_GFXTIM_CLK_DISABLE();
/* GFXTIM interrupt DeInit */
HAL_NVIC_DisableIRQ(GFXTIM_IRQn);
}
}
|
void mx_gfxtim_deinit(void)
{
HAL_GFXTIM_DeInit(&hGFXTIM);
HAL_RCC_GFXTIM_Reset();
HAL_RCC_GFXTIM_DisableClock();
HAL_CORTEX_NVIC_DisableIRQ(GFXTIM_IRQn);
}
|
|
IRQ handle function |
void GFXTIM_IRQHandler(void)
{
HAL_GFXTIM_IRQHandler(&hgfxtim);
}
|
void GFXTIM_IRQHandler(void)
{
HAL_GFXTIM_IRQHandler(&hGFXTIM);
}
|